#include <iostream>
#include <vector>
#include <cstdio>

using namespace std;

const int MAXN = 1000;
vector<int> G[MAXN];
#define pb push_back
int p[MAXN];

void read_tree(int n) {
    int u, v;
    for (int i = 0; i < n - 1; ++i) { // tree has n-1 edges
        cin >> u >> v;
        G[u].pb(v);
        G[v].pb(u);
    }
}

//convert from unrooted tree to rooted tree
void dfs(int u, int fa) {
    int d = G[u].size();
    for (int i = 0; i < d; ++i) {
        int v = G[u][i];
        if(v != fa) dfs(v, p[v] = u);
    }
}

int main() {
    freopen("read_tree.in", "r", stdin);
    int n;
    cin >> n;
    read_tree(n);
    int root = 1;
    p[root] = -1;
    dfs(root, -1);
    for (int i = 0; i < n; ++i) cout << p[i] << ' ';
    cout << endl;
}

